/*
 * LoganoView.java
 */

package logano;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GraphicsDevice;
import java.awt.Rectangle;
import java.awt.Toolkit;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import util.Helper;

/**
 * The application's main frame.
 */
public class LoganoView extends FrameView {

    public LoganoView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
     

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    ;
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                   
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    ;
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = LoganoApp.getApplication().getMainFrame();
            aboutBox = new LoganoAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        LoganoApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        jMenu6 = new javax.swing.JMenu();
        Mbancos = new javax.swing.JMenuItem();
        Mgastos = new javax.swing.JMenuItem();
        Mpagos = new javax.swing.JMenuItem();
        Mtarjetas = new javax.swing.JMenuItem();
        Mcuenta_bancaria = new javax.swing.JMenuItem();
        Mfactura_item = new javax.swing.JMenuItem();
        Mforma_pago = new javax.swing.JMenuItem();
        Mcomprobante = new javax.swing.JMenuItem();
        Mproducto = new javax.swing.JMenuItem();
        Mproveedor = new javax.swing.JMenuItem();
        Mstock = new javax.swing.JMenuItem();
        Mtipo_comprobante = new javax.swing.JMenuItem();
        Musuario = new javax.swing.JMenuItem();
        Mcliente = new javax.swing.JMenuItem();
        Mcheque = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu8 = new javax.swing.JMenu();
        jMenu9 = new javax.swing.JMenu();
        jMenu10 = new javax.swing.JMenu();
        jMenu11 = new javax.swing.JMenu();
        jMenu12 = new javax.swing.JMenu();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        checkbox1 = new java.awt.Checkbox();

        mainPanel.setName("mainPanel"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 590, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 262, Short.MAX_VALUE)
        );

        menuBar.setName("menuBar"); // NOI18N

        helpMenu.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                helpMenuStateChanged(evt);
            }
        });
        helpMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpMenuActionPerformed(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(logano.LoganoApp.class).getContext().getActionMap(LoganoView.class, this);
        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(logano.LoganoApp.class).getContext().getResourceMap(LoganoView.class);
        jMenu6.setText(resourceMap.getString("jMenu6.text")); // NOI18N
        jMenu6.setName("jMenu6"); // NOI18N

        Mbancos.setText(resourceMap.getString("Mbancos.text")); // NOI18N
        Mbancos.setName("Mbancos"); // NOI18N
        Mbancos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MbancosActionPerformed(evt);
            }
        });
        jMenu6.add(Mbancos);

        Mgastos.setText(resourceMap.getString("Mgastos.text")); // NOI18N
        Mgastos.setName("Mgastos"); // NOI18N
        Mgastos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MgastosActionPerformed(evt);
            }
        });
        jMenu6.add(Mgastos);

        Mpagos.setText(resourceMap.getString("Mpagos.text")); // NOI18N
        Mpagos.setName("Mpagos"); // NOI18N
        Mpagos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MpagosActionPerformed(evt);
            }
        });
        jMenu6.add(Mpagos);

        Mtarjetas.setText(resourceMap.getString("Mtarjetas.text")); // NOI18N
        Mtarjetas.setName("Mtarjetas"); // NOI18N
        jMenu6.add(Mtarjetas);

        Mcuenta_bancaria.setText(resourceMap.getString("Mcuenta_bancaria.text")); // NOI18N
        Mcuenta_bancaria.setName("Mcuenta_bancaria"); // NOI18N
        Mcuenta_bancaria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Mcuenta_bancariaActionPerformed(evt);
            }
        });
        jMenu6.add(Mcuenta_bancaria);

        Mfactura_item.setText(resourceMap.getString("Mfactura_item.text")); // NOI18N
        Mfactura_item.setName("Mfactura_item"); // NOI18N
        Mfactura_item.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Mfactura_itemActionPerformed(evt);
            }
        });
        jMenu6.add(Mfactura_item);

        Mforma_pago.setText(resourceMap.getString("Mforma_pago.text")); // NOI18N
        Mforma_pago.setName("Mforma_pago"); // NOI18N
        Mforma_pago.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Mforma_pagoActionPerformed(evt);
            }
        });
        jMenu6.add(Mforma_pago);

        Mcomprobante.setText(resourceMap.getString("Mcomprobante.text")); // NOI18N
        Mcomprobante.setName("Mcomprobante"); // NOI18N
        Mcomprobante.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                McomprobanteActionPerformed(evt);
            }
        });
        jMenu6.add(Mcomprobante);

        Mproducto.setText(resourceMap.getString("Mproducto.text")); // NOI18N
        Mproducto.setName("Mproducto"); // NOI18N
        Mproducto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MproductoActionPerformed(evt);
            }
        });
        jMenu6.add(Mproducto);

        Mproveedor.setText(resourceMap.getString("Mproveedor.text")); // NOI18N
        Mproveedor.setName("Mproveedor"); // NOI18N
        Mproveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MproveedorActionPerformed(evt);
            }
        });
        jMenu6.add(Mproveedor);

        Mstock.setText(resourceMap.getString("Mstock.text")); // NOI18N
        Mstock.setName("Mstock"); // NOI18N
        Mstock.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MstockActionPerformed(evt);
            }
        });
        jMenu6.add(Mstock);

        Mtipo_comprobante.setText(resourceMap.getString("Mtipo_comprobante.text")); // NOI18N
        Mtipo_comprobante.setName("Mtipo_comprobante"); // NOI18N
        Mtipo_comprobante.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Mtipo_comprobanteActionPerformed(evt);
            }
        });
        jMenu6.add(Mtipo_comprobante);

        Musuario.setText(resourceMap.getString("Musuario.text")); // NOI18N
        Musuario.setName("Musuario"); // NOI18N
        Musuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MusuarioActionPerformed(evt);
            }
        });
        jMenu6.add(Musuario);

        Mcliente.setText(resourceMap.getString("Mcliente.text")); // NOI18N
        Mcliente.setName("Mcliente"); // NOI18N
        Mcliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MclienteActionPerformed(evt);
            }
        });
        jMenu6.add(Mcliente);

        Mcheque.setText(resourceMap.getString("Mcheque.text")); // NOI18N
        Mcheque.setName("Mcheque"); // NOI18N
        Mcheque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MchequeActionPerformed(evt);
            }
        });
        jMenu6.add(Mcheque);

        menuBar.add(jMenu6);

        jMenu3.setName("jMenu3"); // NOI18N

        jMenuItem3.setText(resourceMap.getString("jMenuItem3.text")); // NOI18N
        jMenuItem3.setName("jMenuItem3"); // NOI18N
        jMenu3.add(jMenuItem3);

        menuBar.add(jMenu3);

        jMenu8.setName("jMenu8"); // NOI18N
        menuBar.add(jMenu8);

        jMenu9.setText(resourceMap.getString("jMenu9.text")); // NOI18N
        jMenu9.setName("jMenu9"); // NOI18N
        menuBar.add(jMenu9);

        jMenu10.setText(resourceMap.getString("jMenu10.text")); // NOI18N
        jMenu10.setName("jMenu10"); // NOI18N
        menuBar.add(jMenu10);

        jMenu11.setText(resourceMap.getString("jMenu11.text")); // NOI18N
        jMenu11.setName("jMenu11"); // NOI18N
        menuBar.add(jMenu11);

        jMenu12.setText(resourceMap.getString("jMenu12.text")); // NOI18N
        jMenu12.setName("jMenu12"); // NOI18N
        menuBar.add(jMenu12);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 590, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 566, Short.MAX_VALUE)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel))
                .addGap(3, 3, 3))
        );

        jPanel1.setName("jPanel1"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        checkbox1.setLabel(resourceMap.getString("checkbox1.label")); // NOI18N
        checkbox1.setName("checkbox1"); // NOI18N

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void helpMenuStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_helpMenuStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_helpMenuStateChanged

    private void helpMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpMenuActionPerformed
        
    }//GEN-LAST:event_helpMenuActionPerformed

    private void MpagosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MpagosActionPerformed
        FrmListPagos frm = new FrmListPagos();
        Helper.showForm(frm);
    }//GEN-LAST:event_MpagosActionPerformed

    private void McomprobanteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_McomprobanteActionPerformed
       FrmListComprobante frm = new FrmListComprobante();
       Helper.showForm(frm);
    }//GEN-LAST:event_McomprobanteActionPerformed

    private void MbancosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MbancosActionPerformed
       FrmListBanco frm = new FrmListBanco();
        Helper.showForm(frm);
    }//GEN-LAST:event_MbancosActionPerformed

    private void Mcuenta_bancariaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Mcuenta_bancariaActionPerformed
        FrmListCuenta_Bancaria frm = new FrmListCuenta_Bancaria();
       Helper.showForm(frm);
    }//GEN-LAST:event_Mcuenta_bancariaActionPerformed

    private void Mfactura_itemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Mfactura_itemActionPerformed
        FrmListFactura_Item frm = new FrmListFactura_Item();
       Helper.showForm(frm);
    }//GEN-LAST:event_Mfactura_itemActionPerformed

    private void Mforma_pagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Mforma_pagoActionPerformed
        FrmListForma_De_Pago frm = new FrmListForma_De_Pago();
       Helper.showForm(frm);
    }//GEN-LAST:event_Mforma_pagoActionPerformed

    private void MgastosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MgastosActionPerformed
        FrmListGastos frm = new FrmListGastos();
       Helper.showForm(frm);
    }//GEN-LAST:event_MgastosActionPerformed

    private void MproductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MproductoActionPerformed
        FrmListProductos frm = new FrmListProductos();
       Helper.showForm(frm);
    }//GEN-LAST:event_MproductoActionPerformed

    private void MproveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MproveedorActionPerformed
        FrmListProveedor frm = new FrmListProveedor();
       Helper.showForm(frm);
    }//GEN-LAST:event_MproveedorActionPerformed

    private void MstockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MstockActionPerformed
     FrmListStock frm = new FrmListStock();
       Helper.showForm(frm);
    }//GEN-LAST:event_MstockActionPerformed

    private void Mtipo_comprobanteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Mtipo_comprobanteActionPerformed
        FrmListTipo_Comprobante frm = new FrmListTipo_Comprobante();
       Helper.showForm(frm);
    }//GEN-LAST:event_Mtipo_comprobanteActionPerformed

    private void MusuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MusuarioActionPerformed
       FrmListUsuario frm = new FrmListUsuario();
       Helper.showForm(frm);
    }//GEN-LAST:event_MusuarioActionPerformed

    private void MclienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MclienteActionPerformed
       FrmListCliente frm = new FrmListCliente();
       Helper.showForm(frm);
    }//GEN-LAST:event_MclienteActionPerformed

    private void MchequeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MchequeActionPerformed
     FrmListCheque frm = new FrmListCheque();
        Helper.showForm(frm);

    }//GEN-LAST:event_MchequeActionPerformed




    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem Mbancos;
    private javax.swing.JMenuItem Mcheque;
    private javax.swing.JMenuItem Mcliente;
    private javax.swing.JMenuItem Mcomprobante;
    private javax.swing.JMenuItem Mcuenta_bancaria;
    private javax.swing.JMenuItem Mfactura_item;
    private javax.swing.JMenuItem Mforma_pago;
    private javax.swing.JMenuItem Mgastos;
    private javax.swing.JMenuItem Mpagos;
    private javax.swing.JMenuItem Mproducto;
    private javax.swing.JMenuItem Mproveedor;
    private javax.swing.JMenuItem Mstock;
    private javax.swing.JMenuItem Mtarjetas;
    private javax.swing.JMenuItem Mtipo_comprobante;
    private javax.swing.JMenuItem Musuario;
    private java.awt.Checkbox checkbox1;
    private javax.swing.JMenu jMenu10;
    private javax.swing.JMenu jMenu11;
    private javax.swing.JMenu jMenu12;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenu jMenu8;
    private javax.swing.JMenu jMenu9;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
